package main

import "fmt"

func main() {
	var lgc = redis_logic.New(ctx, d.giftRedis, "key:key:key" /*, time.Hour 默认一分钟过期*/ )
	// 记得数据改动时去删改缓存值 d.giftRedis.Del(ctx, "key:key:key")

	// example1:
	var grade model.UserGrade
	hitCache, err := store.New(lgc).Get(&grade, func() (data interface{}, err error) {
		ret, err := d.GetUserGradeDB(ctx, uid) // 查询缓存
		return &ret, err // 注意这里要指针返回
	})
	fmt.Println(grade)

	// example2:
	var uInfo model.UserInfo
	hitCache, err := store.New(lgc).Get(&uInfo, func() (data interface{}, err error) {
		ret, err := s.mgr.GetUserInfo(ctx, uid) // 远程调用
		return &ret, err
	})
	fmt.Println(uInfo)

	// example3:
	var sum int64
	hitCache, err := store.New(lgc).Get(&uInfo, func() (data interface{}, err error) {
		ret, err := d.GetPaySum(ctx, uid)
		return &ret, err
	}
	fmt.Println(sum)
}